#include <stdio.h>
#include <sys/param.h>
#include <fetch.h>
#include <string.h>
#include <stdlib.h>
#include <json/json.h>
int main(int argc,char **argv)
{
	struct url_stat *us=calloc(1,sizeof(struct url_stat));
	FILE *fp=fetchXGetURL("http://192.168.2.5/listdir.php?path=/bin",us,NULL);
	if(!fp)
	{
		printf("%d\n",fetchLastErrCode);
		printf("%s\n",fetchLastErrString);
		exit(1);
	}
	if(us->size == -1)
	{
		printf("%s\n","url do not have Content-Length Header!");
		exit(2);
	}
	char *buf=calloc(1,us->size);
	fread(buf,us->size,1,fp);
	printf("%s\n",buf);
	struct json_object *jo=json_tokener_parse(buf);
	enum json_type jt=json_object_get_type(jo);
	printf("%d\n",jt);
	struct array_list *al=json_object_get_array(jo);
	int l=array_list_length(al);
	printf("array length: %d\n",l);
	struct json_object *jo2;
	for(int i=0;i<l;i++)
	{
		jo2=json_object_array_get_idx(jo,i);
		//printf("%s\n",json_object_to_json_string(jo2));
		json_object_object_foreach(jo2,k,v)
		{
			printf("%s --- %s\n",k,json_object_to_json_string(v));
		}
	}
	free(buf);
	return 0;
}

